package net.miranti.opmov;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

import net.miranti.opmov.client.Airport;

@Entity
@NamedQueries({
	@NamedQuery(name = OperationalMovement.FIND_BY_AIRPORT, 
			query = OperationalMovement.FIND_BY_AIRPORT_QUERY),
	@NamedQuery(name = OperationalMovement.FIND_ALL_AIRPORTS,
			query = OperationalMovement.FIND_ALL_AIRPORTS_QUERY)
})
public class OperationalMovement implements Serializable{
	public static enum Type { AIRCRAFT, PASSENGER, CARGO, MAIL }
	
	public final static String FIND_BY_AIRPORT = "FIND_OPMOV_BY_AIRPORT";
	private final static String FIND_BY_AIRPORT_QUERY = 
		"from OperationalMovement o where o.airport.code = ?";
	
	public final static String FIND_ALL_AIRPORTS = "FIND_OPMOV_ALL_AIRPORTS";
	private final static String FIND_ALL_AIRPORTS_QUERY = 
		"select period, type, sum(domestic), sum(international) "
		+ "from OperationalMovement group by period, type";
	
	@Id
	@GeneratedValue
	private Long id;
	private Type type;
	private Integer domestic, international;
	private String period;
	
	@ManyToOne
	private Airport airport;
	
	OperationalMovement() {}

	public OperationalMovement(Type type, 
			Airport airport, String period,
			Integer domestic, Integer international) {
		this.type = type;
		this.domestic = domestic;
		this.international = international;
		this.period = period;
		this.airport = airport;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Type getType() {
		return type;
	}

	public void setType(Type type) {
		this.type = type;
	}

	public Integer getDomestic() {
		return domestic;
	}

	public void setDomestic(Integer domestic) {
		this.domestic = domestic;
	}

	public Integer getInternational() {
		return international;
	}

	public void setInternational(Integer international) {
		this.international = international;
	}

	public String getPeriod() {
		return period;
	}

	public void setPeriod(String period) {
		this.period = period;
	}

	public Airport getAirport() {
		return airport;
	}

	public void setAirport(Airport airport) {
		this.airport = airport;
	}
}
